Drag = {	
	selectionDragFromEvents: {
		selectstart: function() {		
	        return false;
	    },
	    dragstart: function(ev) {	
	        ev.dataTransfer.effectAllowed = "copy";
	        ev.dataTransfer.setDragImage(ev.target, 0, 0);
	        Vari.DragType = "selection";
	        
	        var src = $(ev.target).closest(".drag_fld");
	        Vari.srcId = src.prop("id");
	        
	        ev.dataTransfer.setData("from", "selection");
	        ev.dataTransfer.setData("src", Vari.srcId);
	        
	        return true;
	    },
	    drag: function(ev) {
	        return true;
	    },
	    dragend: function(ev) {
	        ev.dataTransfer.clearData("text");
	        return false;
	    }
	},
	selectionDragToEvents: {
	    dragenter: function(ev) {
	        return true;
	    },
		dragover: function(ev) {
			ev.preventDefault();
			return true;
	    },
	    drop: function(ev) {	    	
	    	if (ev.dataTransfer.getData("from") != "selection") {
	    		return false;
	    	}

	    	var src = ev.dataTransfer.getData("src");
			var utilName = Util.capFirstLetter(src) + "Util";
			eval(utilName + ".create()");
		    
		    return false;
		}
	},
	
	fieldDragFromEvents: {
		selectstart: function() {		
	        return false;
	    },
	    dragstart: function(ev) {	    	
	        ev.dataTransfer.effectAllowed = "move";
	        ev.dataTransfer.setDragImage(ev.target, 0, 0);
	        Vari.DragType = "field";
	        
	        var src = $(ev.target);
	        var srcName = src.prop("tagName");
	        if (srcName.toLowerCase() == "a") {
	        	src = src.parent(".drag_fld");		        	
	        }
	        Vari.srcId = src.prop("id");
	        
	        ev.dataTransfer.setData("from", "field");
	        ev.dataTransfer.setData("src", Vari.srcId);
	        
	        return true;
	    },
	    drag: function(ev) {
	        return true;
	    },
	    dragend: function(ev) {
	        ev.dataTransfer.clearData("text");
	        return false;
	    }
    },
	fieldDragToEvents: {
	    dragenter: function(ev) {
	        return true;
	    },
		dragover: function(ev) {
	        ev.preventDefault();
			return true;
	    },
	    drop: function(ev) {
	    	var id = $(ev.target).closest(".fieldset.editing").attr("id");
	    	if (ev.dataTransfer.getData("from") == "selection") { // drag to add
		    	var src = ev.dataTransfer.getData("src");
		    	var utilName = Util.capFirstLetter(src) + "Util";
		    	eval(utilName + ".create(id)");

	    	} else { // drag to move
		    	var src = ev.dataTransfer.getData("src");		    	
		    	var srcEle = $("#"+src);
		    	var srcId = srcEle.attr("id");
		    	
		    	var distEle = $(this);
		    	var distId = distEle.attr("id");
		    	
		    	var newEle = srcEle.clone(true);
				newEle.insertAfter(distEle);
				srcEle.remove();
				
		    	var s = Vari.fieldMap.get(srcId);
		    	var d = Vari.fieldMap.get(distId);

				Vari.frm.get("fields").removeObject(s);				
				var pos = Vari.frm.get("fields").indexOf(d) + 1;
				Vari.frm.get("fields").insertAt(pos, s);
				//console.log(Vari.frm.get("fields"));
	    	}
	    	return false;
		}
	},
	fieldSetEvents: {
		mouseenter: function(ev) {
			var fieldSet = $(ev.target).closest(".fieldset.editing");
			var spanRemove = $('<span class="handle icon-remove" />');
			spanRemove.appendTo(fieldSet);
			//spanRemove.click( function () { alert(1); });
	        return false;
	    },
	    mouseleave: function(ev) {
	    	var fieldSet = $(ev.target).closest(".fieldset.editing");
	    	fieldSet.find('span.handle').remove();
	        return false;
	    },
	    click: function(ev) {
	    	var fieldSet = $(ev.target).closest(".fieldset.editing");
			var id = fieldSet.attr("id");
			var code = Vari.fieldMap.get(id).get("type");
	    	if ($(ev.target).hasClass("icon-remove")) {	   
	    		FieldUtil.removeField(id, code);
	    	} else {
	    		FieldUtil.editFieldSettings(id, code);
	    	}	 
	    	return false;
	    }
	}
};